package com.lgc.javathread.volatileTest;

public class Main1 {
    static volatile int m=0;

    public  static void increase(){
        // m++操作不具有原子性
        m++;
    }

    public static void main(String[] args) throws InterruptedException {
        /*for (int i = 0; i < 100; i++) {
            new Thread(()->{
                for (int j = 0; j < 50; j++) {
                    increase();
                }
            }).start();
        }*///0，分析为什么是0
        //改成下边的方式
        Thread[] arr = new Thread[100];
        for (int i = 0; i < 100; i++) {
            arr[i] =new Thread(()->{
                for (int j = 0; j < 50; j++) {
                    increase();
                }
            });
            arr[i].start();
            arr[i].join();
        }

        System.out.println(m);
    }
}
